Completed
Push — master ( 539e21...edbb3f )
by Rafael S.
01:56
created

minibuffer.js ➔ unpack   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
dl 0
loc 1
rs 10
nop 3
1
/*
2
 * Copyright (c) 2018 Rafael da Silva Rocha.
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining
5
 * a copy of this software and associated documentation files (the
6
 * "Software"), to deal in the Software without restriction, including
7
 * without limitation the rights to use, copy, modify, merge, publish,
8
 * distribute, sublicense, and/or sell copies of the Software, and to
9
 * permit persons to whom the Software is furnished to do so, subject to
10
 * the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
 *
23
 */
24
25
/**
26
 * @fileoverview Externs for minibuffer 0.3.0
27
 * @see https://github.com/rochars/minibuffer
28
 * @externs
29
 */
30
31
/** @type {!Object} */
32
var theType = {
33
	bits: 0,
34
	signed: false,
35
	fp: false,
36
	be: false
37
};
38
39
/**
40
 * Read a string of UTF-8 characters from a byte buffer.
41
 * @param {!Uint8Array|!Array<number>} buffer A byte buffer.
42
 * @param {number=} index The buffer index to start reading.
43
 * @param {number=} end The buffer index to stop reading, non inclusive.
44
 *   Assumes buffer length if undefined.
45
 * @return {string}
46
 */
47
function unpackString(buffer, index=0, end=buffer.length) {}
48
49
/**
50
 * Write a string of UTF-8 characters as a byte buffer.
51
 * @param {string} str The string to pack.
52
 * @return {!Array<number>} The UTF-8 string bytes.
53
 */ 
54
function packString(str) {}
0 ignored issues
show
Unused Code introduced by
The parameter str is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
55
56
/**
57
 * Write a string of UTF-8 characters to a byte buffer.
58
 * @param {string} str The string to pack.
59
 * @param {!Uint8Array|!Array<number>} buffer The output buffer.
60
 * @param {number=} index The buffer index to start writing.
61
 *   Assumes zero if undefined.
62
 * @return {number} The next index to write in the buffer.
63
 */
64
function packStringTo(str, buffer, index=0) {}
65
66
// Numbers
67
/**
68
 * Pack a number as a byte buffer.
69
 * @param {number} value The number.
70
 * @param {!Object} theType The type definition.
71
 * @return {!Array<number>} The packed value.
72
 * @throws {Error} If the type definition is not valid.
73
 * @throws {Error} If the value is not valid.
74
 */
75
function pack(value, theType) {}
0 ignored issues
show
Unused Code introduced by
The parameter theType is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter value is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
76
77
/**
78
 * Pack a number to a byte buffer.
79
 * @param {number} value The value.
80
 * @param {!Object} theType The type definition.
81
 * @param {!Uint8Array|!Array<number>} buffer The output buffer.
82
 * @param {number=} index The buffer index to write. Assumes 0 if undefined.
83
 * @return {number} The next index to write.
84
 * @throws {Error} If the type definition is not valid.
85
 * @throws {Error} If the value is not valid.
86
 */
87
function packTo(value, theType, buffer, index=0) {}
88
89
/**
90
 * Pack an array of numbers as a byte buffer.
91
 * @param {!Array<number>|!TypedArray} values The values.
92
 * @param {!Object} theType The type definition.
93
 * @return {!Array<number>} The packed values.
94
 * @throws {Error} If the type definition is not valid.
95
 * @throws {Error} If any of the values are not valid.
96
 */
97
function packArray(values, theType) {}
0 ignored issues
show
Unused Code introduced by
The parameter values is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter theType is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
98
99
/**
100
 * Pack a array of numbers to a byte buffer.
101
 * @param {!Array<number>|!TypedArray} values The value.
102
 * @param {!Object} theType The type definition.
103
 * @param {!Uint8Array|!Array<number>} buffer The output buffer.
104
 * @param {number=} index The buffer index to start writing.
105
 *   Assumes zero if undefined.
106
 * @return {number} The next index to write.
107
 * @throws {Error} If the type definition is not valid.
108
 * @throws {Error} If the value is not valid.
109
 */
110
function packArrayTo(values, theType, buffer, index=0) {}
111
112
/**
113
 * Unpack a number from a byte buffer.
114
 * @param {!Uint8Array|!Array<number>} buffer The byte buffer.
115
 * @param {!Object} theType The type definition.
116
 * @param {number=} index The buffer index to read. Assumes zero if undefined.
117
 * @return {number}
118
 * @throws {Error} If the type definition is not valid
119
 * @throws {Error} On bad buffer length.
120
 */
121
function unpack(buffer, theType, index=0) {}
122
123
/**
124
 * Unpack an array of numbers from a byte buffer.
125
 * @param {!Uint8Array|!Array<number>} buffer The byte buffer.
126
 * @param {!Object} theType The type definition.
127
 * @param {number=} index The buffer index to start reading.
128
 *   Assumes zero if undefined.
129
 * @param {number=} end The buffer index to stop reading.
130
 *   Assumes the buffer length if undefined.
131
 * @param {boolean=} safe If set to false, extra bytes in the end of
132
 *   the array are ignored and input buffers with insufficient bytes will
133
 *   output a empty array. If safe is set to true the function
134
 *   will throw a 'Bad buffer length' error. Defaults to false.
135
 * @return {!Array<number>}
136
 * @throws {Error} If the type definition is not valid
137
 */
138
function unpackArray(
139
	buffer, theType, index=0, end=buffer.length, safe=false) {}
140
141
/**
142
 * Unpack a array of numbers to a typed array.
143
 * @param {!Uint8Array|!Array<number>} buffer The byte buffer.
144
 * @param {!Object} theType The type definition.
145
 * @param {!TypedArray|!Array<number>} output The output array.
146
 * @param {number=} index The buffer index to start reading.
147
 *   Assumes zero if undefined.
148
 * @param {number=} end The buffer index to stop reading.
149
 *   Assumes the buffer length if undefined.
150
 * @param {boolean=} safe If set to false, extra bytes in the end of
151
 *   the array are ignored and input buffers with insufficient bytes will
152
 *   write nothing to the output array. If safe is set to true the function
153
 *   will throw a 'Bad buffer length' error. Defaults to false.
154
 * @throws {Error} If the type definition is not valid
155
 */
156
function unpackArrayTo(
157
	buffer, theType, output, index=0, end=buffer.length, safe=false) {}
158